﻿var burl1 = "hangqing.ashx";
//burl1="http://172.28.1.72:8080";
function getUrl() {
    json = 100; t = 1;
    p = $("#hidP").val();
    c = $("#hidT").val();
    t = $("#hidTy").val();
    i = 1;
    id = $("#hidCode").val();
    return "?id=" + id + "&t=" + t + "&p=" + p + "&i=" + i + "&json=" + json + "&c=" + c;
}
function getData() {
//alert("getData");
    purl = burl1 + getUrl();
    if (isNotIE) purl=purl+"&jsoncallback=?";
    else {
        var ran=Math.random();
        purl=purl+"&ran="+ran.toString();
    }
    //alert(purl);
    //alert("a");
    if (isReady) {
        //alert("b");
        $.getJSON(purl, dataLoaded);
    } else {
    //alert("c");
        $.getJSON(purl, dataLoadedFirst);
    }
}
function dataLoaded(data) {
//alert("dataLoaded");
    try {
        //alert(data);
        if (data == undefined) {
            dataLoadError();
            return;
        }
        chart1.refreshData("json", data);
    } catch (ex) {
        dataLoadError();
        //alert(ex.name + ":" + ex.message + ":" + ex.at + ":" + ex.text);
    }
}
function dataLoadedFirst(data) {
    try {
        if (data == undefined) {
            return;
        }
    //alert("dataLoadedFirst");
     
        firstData = data;        
        if(chart1.refreshData("json", data)){
            //alert("fasdf");
            invReady = setInterval(getData, 20*1000);
            isReady = true;
        }
        else{
            inv = setInterval(firstAdd, 1000);
        }

    } catch (ex) {
        //alert("err");
        inv = setInterval(firstAdd, 1000);
        //dataLoadError();
        //alert(ex.name + ":" + ex.message + ":" + ex.at + ":" + ex.text);
    }
}
function firstAdd() {
    //if (chart1.refreshData("json", firstData)) {
    try{
        chart1.refreshData("json", firstData);
        //alert("clearFirst");
        if (inv) clearInterval(inv);
        invReady = setInterval(getData, 20*1000);
        isReady = true;
        //alert("fin");
    //}
     } catch (ex) {
        //alert("cant in");
     }
}

function dataLoadError() {
    //if (inv) clearInterval(getData, 5 * 1000);
    $("#txtCode").val("");
    alert("获得数据出错，请重新输入股票代码！");
}